package com.wangjiyuan.giftshuo.ui.fragment.listtop.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wangjiyuan.giftshuo.R;
import com.wangjiyuan.giftshuo.bean.listtopbean.commentbean.CommentBean;
import com.wangjiyuan.giftshuo.ui.fragment.listtop.helper.RecyclerViewAdapterHelper;

import java.util.List;

/**
 * Created by ZangSyeriong on 2016/11/22.
 *
 * 榜单评论区
 *
 */

public class CommentRecyclerViewAdapter extends RecyclerViewAdapterHelper<Object>{

    public static final int IMG_TALK = 0, TALK = 1;
    private CommentBean.DataBean.CommentsBean commentsBean
             = new CommentBean.DataBean.CommentsBean();


    public CommentRecyclerViewAdapter(Context context, List<Object> list) {
        super(context, list);
    }

    @Override
    public int getItemViewType(int position) {
        Object object = mList.get(position);
        if (object instanceof CommentBean.DataBean.CommentsBean.ImagesBean){
            return IMG_TALK;
        }
        return TALK;
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        switch (viewType){
            case IMG_TALK:
                view = mInflater.inflate(R.layout.item_rv_comment_imgtalk, parent, false);
                return new CommentRecyclerViewAdapter.MyImgTalkViewHolder(view);
            case TALK:
                view = mInflater.inflate(R.layout.item_rv_comment_talk, parent, false);
                return new CommentRecyclerViewAdapter.MyTalkViewHolder(view);
        }
        return null;
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        commentsBean = (CommentBean.DataBean.CommentsBean) mList.get(position);
        if (holder instanceof CommentRecyclerViewAdapter.MyImgTalkViewHolder){
            Glide.with(mContext)
                    .load(commentsBean.getUser().getAvatarUrl())
                    .placeholder(R.mipmap.post_place_holder_image)
                    .into(((MyImgTalkViewHolder) holder).img_comment_icon_imgTalk);

            ((MyImgTalkViewHolder) holder).tv_comment_title_imgTalk.setText(
                    commentsBean.getUser().getNickname());
            ((MyImgTalkViewHolder) holder).tv_comment_time_imgTalk.setText(commentsBean.getCreatedAt()+"");
            ((MyImgTalkViewHolder) holder).tv_comment_context_imgTalk.setText(
                    commentsBean.getContent());
        }else if (holder instanceof CommentRecyclerViewAdapter.MyTalkViewHolder){
            Glide.with(mContext)
                    .load(commentsBean.getUser().getAvatarUrl())
                    .placeholder(R.mipmap.post_place_holder_image)
                    .into(((MyTalkViewHolder) holder).img_comment_icon);
            ((MyTalkViewHolder) holder).tv_comment_title.setText(
                    commentsBean.getUser().getNickname());

            ((MyTalkViewHolder) holder).tv_comment_context.setText(commentsBean.getCreatedAt()+"");
            ((MyTalkViewHolder) holder).tv_comment_talk.setText(
                    commentsBean.getContent());
        }

    }
    static class MyTalkViewHolder extends RecyclerView.ViewHolder{

        private ImageView img_comment_icon;
        private TextView tv_comment_title, tv_comment_context, tv_comment_talk;

        public MyTalkViewHolder(View itemView) {
            super(itemView);

            img_comment_icon = (ImageView) itemView.findViewById(R.id.img_comment_icon);
            tv_comment_title = (TextView) itemView.findViewById(R.id.tv_comment_title);
            tv_comment_context = (TextView) itemView.findViewById(R.id.tv_comment_context);
            tv_comment_talk = (TextView) itemView.findViewById(R.id.tv_comment_talk);

        }
    }
    static class MyImgTalkViewHolder extends RecyclerView.ViewHolder{

        private ImageView img_comment_icon_imgTalk,
                img_comment_imgTalk;
        private TextView tv_comment_title_imgTalk,
                tv_comment_time_imgTalk,
                tv_comment_context_imgTalk;

        public MyImgTalkViewHolder(View itemView) {
            super(itemView);

            img_comment_icon_imgTalk = (ImageView) itemView.findViewById(R.id.img_comment_icon_imgTalk);
            img_comment_imgTalk = (ImageView) itemView.findViewById(R.id.img_comment_imgTalk);
            tv_comment_title_imgTalk = (TextView) itemView.findViewById(R.id.tv_comment_title_imgTalk);
            tv_comment_time_imgTalk = (TextView) itemView.findViewById(R.id.tv_comment_time_imgTalk);
            tv_comment_context_imgTalk = (TextView) itemView.findViewById(R.id.tv_comment_context_imgTalk);

        }
    }
}
